

DEFINE VARIABLE voutput AS CHARACTER  NO-UNDO initial "hkwopklist.csv".
define variable vappend as logical initial no.


for first code_mstr no-lock where code_fldname = "exptab2csv" and code_value = "output":
        assign voutput  = code_cmmt + voutput.
end.
for first code_mstr no-lock where code_fldname = "wopklist" and code_value = "append":
         if code_cmmt = "yes" then vappend = yes.
end.


if vappend then do:
    output to value(voutput) append.
end.
else do:
    output to value(voutput).
end.


FOR EACH wo_mstr NO-LOCK WHERE wo_site='500' AND wo_nbr >= "W" and wo_status = "R":
    FOR EACH wod_det NO-LOCK WHERE  wod_lot = wo_lot break by wod_part:
        ACCUM wod_qty_req (SUM  BY wod_part).
        if LAST-OF(wod_part) then do:
            FIND FIRST pt_ NO-LOCK WHERE pt_part=wod_part NO-ERROR.
            export delimiter "," wo_nbr wo_lot  wo_part wod_part ACCUM SUM BY wod_part wod_qty_req  pt_group STRING((IF wo__dte01 =? THEN wo_rel_date ELSE wo__dte01),'9999-99-99').
        end.
    END.
END.
output close.

quit.
